import math
from vec import Vec4
class Matrix4x4:
    def __init__(self):
        self.rows = 4
        self.cols = 4
        self.m = [[0 for i in range(self.cols)] for j in range(self.rows)]
    
    def identity(self):
        for i in range(self.rows):
            self.m[i][i] = 1

    def zero(self):
        for i in range(self.rows):
            for j in range(self.cols):
                self.m[i][j] = 0
    
    def set_matrix(self, arr):
        self.m = arr

    def set_val(self, r, c, val):
        self.m[r][c] = val

    def make_matrix(self, vx, vy, vz):
        self.set_col(0, vx)
        self.set_col(1, vy)
        self.set_col(2, vz)
        self.set_col(3, Vec4(1, 1, 1, 1))

    def mul_vec4(self, v):
        return self.get_col(0) * v.x + self.get_col(1) * v.y + self.get_col(2) * v.z + self.get_col(3) * v.w

    def mul_m4x4(self, m):
        result = Matrix4x4()
        for i in range(self.rows):
            for j in range(self.cols):
                result.set_val(i, j, self.get_row(i).dot(m.get_col(j)))
        return result

    def set_col(self, index, v):
        self.m[index][0] = v.x
        self.m[index][1] = v.y
        self.m[index][2] = v.z
        self.m[index][3] = v.w

    def get_col(self, index):
        result = []        
        for i in range(self.rows):
            result.append(self.m[index][i])

        return Vec4(result[0], result[1], result[2], result[3])

    def get_row(self, index):
        result = []        
        for i in range(self.cols):
            result.append(self.m[i][index])

        return Vec4(result[0], result[1], result[2], result[3])

    def output(self):
        print(self.m)
        
        